<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">模板信息</ui:define>
    <ui:define name="content">
        <h:form id="modelInfoForm" enctype="multipart/form-data">
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="right">
                        <p:commandButton value="编辑" icon="fa fa-edit"
                                         actionListener="#{loanActivityModelInfoBean.changeStatusToEdit}"
                                         process="@this"
                                         update="@form" rendered="#{loanActivityModelInfoBean.isView()}"/>
                        <p:commandButton value="保存" icon="fa fa-save"
                                         actionListener="#{loanActivityModelInfoBean.onSave()}"
                                         update="@form"
                                         rendered="#{loanActivityModelInfoBean.isAdd() || loanActivityModelInfoBean.isEdit()}"/>
                        <p:button value="返回" icon="fa fa-reply-all" href="#{currentUserBean.back}"/>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-g ui-fluid" style="padding-top: 30px;">
                <div class="ui-g-12 ">
                    <div class="ui-g-12 card">
                        <h1>基础信息</h1>

                        <div class="ui-g-12">
                            <div class="ui-g-2">
                                <p:outputLabel value="模板名称"/>
                            </div>
                            <div class="ui-g-4">
                                <p:inputText id="modelName" value="#{loanActivityModelInfoBean.$.modelName}"
                                             disabled="#{loanActivityModelInfoBean.isView()}"/>
                            </div>
                            <div class="ui-g-2">
                                <p:outputLabel value="模板备注"/>
                            </div>
                            <div class="ui-g-4">
                                <p:inputText id="modelRemark" value="#{loanActivityModelInfoBean.$.modelRemark}"
                                             disabled="#{loanActivityModelInfoBean.isView()}"/>
                            </div>
                            <div class="ui-g-2">
                                <p:outputLabel value="跳转链接"/>
                            </div>
                            <div class="ui-g-4">
                                <p:inputText id="targetUrl" value="#{loanActivityModelInfoBean.$.targetUrl}"
                                             disabled="#{loanActivityModelInfoBean.isView()}"/>
                            </div>

                            <div class="ui-g-2">
                                <p:outputLabel for="modelType" value="模板类型"/>
                            </div>

                            <div class="ui-g-4">
                                <p:selectOneMenu id="modelType" value="#{loanActivityModelInfoBean.$.modelType}" disabled="#{loanActivityModelInfoBean.isView()}">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItem itemLabel="贷款活动" itemValue="0"/>
                                    <f:selectItem itemLabel="信用卡活动" itemValue="1"/>
                                    <f:selectItem itemLabel="单图文模板" itemValue="2"/>
                                </p:selectOneMenu>
                            </div>
                        </div>

                        <div class="ui-g-12 ">
                            <p:commandButton value="新增属性" icon="fa fa-plus" style="width: 120px;margin-bottom: 5px"
                                             actionListener="#{loanActivityModelInfoBean.onAddContent}"
                                             oncomplete="PF('model-content-adding').show()" disabled="#{loanActivityModelInfoBean.isView()}"/>

                            <div class="ui-g-12">
                                <p:dataTable id="contentRecordDataTable"
                                             style="width: 100%;text-align:center"
                                             rowIndexVar="rowIndex" var="record"
                                             value="#{loanActivityModelInfoBean.modelContentList}">
                                    <p:column headerText="操作" exportable="false">
                                        <p:splitButton icon="fa fa-eye"
                                                       process="@form" actionListener="#{loanActivityModelInfoBean.onSeeContent(rowIndex)}"
                                                       update="@form" disabled="#{loanActivityModelInfoBean.isView()}" oncomplete="PF('model-content-adding').show()">
                                            <p:menuitem value="删除" icon="fa fa-fw fa-remove"
                                                        action="#{loanActivityModelInfoBean.onDeleteContent(rowIndex)}"
                                                        process="@this" update="contentRecordDataTable">
                                                <p:confirm header="删除" message="确定删除该属性信息吗？"/>
                                            </p:menuitem>
                                        </p:splitButton>
                                    </p:column>
                                    <p:column headerText="title" style="text-align:center;">
                                        <h:outputText value="#{record.name}" />
                                    </p:column>
                                    <p:column headerText="key名称" style="text-align:center;">
                                        <h:outputText value="#{record.content}" />
                                    </p:column>
                                    <p:column headerText="类型" style="text-align:center;">
                                        <h:outputText value="输入框" rendered="#{record.type==0}"/>
                                        <h:outputText value="图片" rendered="#{record.type==1}"/>
                                        <h:outputText value="图文" rendered="#{record.type==2}"/>
                                        <h:outputText value="时间" rendered="#{record.type==3}"/>
                                        <h:outputText value="单选框" rendered="#{record.type==4}"/>
                                        <h:outputText value="列表1" rendered="#{record.type==5}"/>
                                    </p:column>
                                    <p:column headerText="备注" style="text-align:center;">
                                        <h:outputText value="#{record.remark}"/>
                                    </p:column>
                                </p:dataTable>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <ui:include src="model-content-dialog.xhtml"/>
        </h:form>
    </ui:define>
</ui:composition>